package connessione;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Database {
	
	protected Connection connection;
	public static final String USERNAME = "root";
	public static final String PASSWORD = "root";
	protected ResultSet rst = null;
	protected Statement st = null;
	protected PreparedStatement pst = null;
	
	
	
	public Database () {
		try {
			String driver = "com.mysql.jdbc.Driver";
			String url = "jdbc:mysql://127.0.0.1:3306/dbonomastici";
			Class.forName(driver);
			connection = DriverManager.getConnection(url, USERNAME, PASSWORD);
		} 
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
		catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public boolean isClosed() {
		
		boolean closed = false;
		try {
			closed = connection.isClosed();
		}catch(SQLException ex) {
			ex.printStackTrace();
		}
		return closed;
	}
	
	public void close() {
		try  {
		if( connection != null ) connection.close();
		}
		catch(Exception ex){
			ex.printStackTrace();
		}
	}
}
